package de.hsowl.tod4a.server;

import java.io.IOException;
import java.util.List;

import org.jdom.Document;
import org.jdom.JDOMException;

import de.hsowl.tod4a.global.exception.ObjectDatabaseException;
import de.hsowl.tod4a.global.model.ObjectMap;

public abstract interface ObjectManager {

	/**
	 * Stores Objects found within an provided XML message
	 * 
	 * @param xmlMessage
	 * @return true-> storing successfull; false->storing failed
	 * @throws ObjectDatabaseException
	 */
	public abstract boolean store(String xmlMessage) throws ObjectDatabaseException;

	/**
	 * Stores Objects within a List.
	 * 
	 * @param list
	 * @return
	 */
	public abstract boolean store(List<ObjectMap> list);

	/**
	 * Stores Objects within a List
	 * 
	 * @param list
	 * @return
	 */
	@Deprecated
	public abstract boolean storeObjects(List<ObjectMap> list);

	/**
	 * Stores Objects within a List
	 * 
	 * @param list
	 * @return
	 */
	public abstract boolean storeObjects2(List<ObjectMap> list);

	/**
	 * Removes one or many objects contained in the xmlmessage
	 * 
	 * @param xmlMessage
	 * @return
	 */
	public abstract void remove(final String xmlMessage);

	/**
	 * Adds an user to /tod4a/users.xml. Only users in this file can connect via
	 * Client Server to the database
	 * 
	 * @param xmlMessage
	 * @throws Exception
	 */
	public abstract void addUser(String xmlMessage) throws Exception;

	/**
	 * Adds an user to /tod4a/users.xml. Only users in this file can connect via
	 * Client Server to the database
	 * 
	 * @param name
	 * @param password
	 * @throws IOException
	 * @throws JDOMException
	 */
	public abstract void addUser(String name, String password) throws IOException, JDOMException;

	/**
	 * Searches for a user by name
	 * 
	 * @param doc
	 * @param name
	 * @return
	 */
	public abstract boolean getUser(Document doc, String name);

	/**
	 * Check wether a user is valid
	 * 
	 * @param doc
	 * @param name
	 * @return
	 * @throws IOException
	 * @throws JDOMException
	 */
	public abstract boolean checkLoginCredentials(String name, String password) throws JDOMException, IOException;

	/**
	 * Searches for objects by their classname described in a xml message
	 * 
	 * @param clazzXml
	 *            - name of the class
	 * @return
	 * @throws Exception
	 */
	public abstract String getByClass(String clazzXml) throws Exception;

	/**
	 * returns all instances of a spezific class and all children
	 * 
	 * @param clazz
	 * @return
	 * @throws Exception
	 */
	public abstract List<ObjectMap> getByClazz(String clazz, int depth) throws Exception;

	/**
	 * Searches for objects by their names and class
	 * 
	 * @param name
	 * @return
	 * @throws Exception
	 */
	public abstract List<ObjectMap> getByName(final String name, String className, int depth) throws Exception;

	/**
	 * Searches for objects by their names.<br>
	 * NOTE: All types of objects will returned
	 * 
	 * @param name
	 * @return
	 * @throws Exception
	 */
	public abstract List<ObjectMap> getByName(final String name, int depth) throws Exception;

	/**
	 * Removes a user by a xml message. This user is no longer able to connect
	 * to the server. Local access is allowed.
	 * 
	 * @param username
	 * @return
	 * @throws JDOMException
	 * @throws IOException
	 */
	public abstract void removeUser(String xmlMessage) throws JDOMException, IOException;

	/**
	 * Removes a user by its name. This user is no longer able to connect to the
	 * server. Local access is allowed.
	 * 
	 * @param username
	 * @return
	 * @throws JDOMException
	 * @throws IOException
	 */
	public abstract boolean removeUser_(String username) throws JDOMException, IOException;

	/**
	 * Starts a transaction
	 * 
	 * @throws ObjectDatabaseException
	 */
	public abstract void begin() throws ObjectDatabaseException;

	/**
	 * Ends a transaction
	 */
	public abstract void stop();

	/**
	 * Starts a rollback for all classes
	 * 
	 * @param num
	 * @throws JDOMException
	 * @throws IOException
	 */
	public abstract void rollback(int num) throws ObjectDatabaseException;
}
